#include "Shifter.h"

bool Shifter::getFinished()
{
	return finished;
}

BitArray Shifter::get()
{
	return array;
}

void Shifter::set(BitArray a)
{
	array = a;
}

Shifter::Shifter(unsigned int length, BitPointer& b, bool dir, bool i)
{
	bit = b;
	finished = false;
	io = i;
	direction = dir;
	array = BitArray(length);
	if(dir == true)
		index = 0;
	else
		index = length - 1;
}

Shifter::Shifter()
{
	array = BitArray();
}

void Shifter::shift()
{
	if(io == false) //we are getting input from shifter
		array[index].setBit(bit.getBit());
	else
		bit.setBit(array[index].getBit());
	finished = false;
	if(direction == true) //if true increment else decrement
		index++;
	else
		index--;
	//determine if I am finished shifting data.
	unsigned int t = -1;
	if(index == t)
	{
		index = array.size()-1;
		finished = true;
	}
	else if(index == array.size())
	{
		index = 0;
		finished = true;
	}
}

